home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / ListPair.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  1.9 KB  |  42 lines  |  [TEXT/R*ch]

  1. (* ListPair -- SML Standard Library *)
  2.  
  3. val zip    : 'a list * 'b list -> ('a * 'b) list
  4. val unzip  : ('a * 'b) list -> 'a list * 'b list
  5. val map    : ('a * 'b -> 'c)   -> 'a list * 'b list -> 'c list
  6. val app    : ('a * 'b -> unit) -> 'a list * 'b list -> unit
  7. val all    : ('a * 'b -> bool) -> 'a list * 'b list -> bool
  8. val exists : ('a * 'b -> bool) -> 'a list * 'b list -> bool
  9.  
  10. (* These functions process pairs of lists.  No exception is raised
  11.    when the lists are found to be of unequal length.  Instead the
  12.    excess elements from the longer list are disregarded.
  13.  
  14.    [zip (xs, ys)] returns the list of pairs of corresponding elements
  15.    from xs and ys.  
  16.  
  17.    [unzip xys] returns a pair (xs, ys), where xs is the list of first
  18.    components of xys, and ys is the list of second components from
  19.    xys.  Hence zip (unzip xys) has the same result and effect as xys.
  20.  
  21.    [map f (xs, ys)] applies function f to the pairs of corresponding
  22.    elements of xs and ys and returns the list of results.  Hence 
  23.    map f (xs, ys) has the same result and effect as List.map f (zip (xs, ys)).
  24.  
  25.    [app f (xs, ys)] applies function f to the pairs of corresponding
  26.    elements of xs and ys and returns ().  Hence app f (xs, ys) has the
  27.    same result and effect as List.app f (zip (xs, ys)).
  28.  
  29.    [all p (xs, ys)] applies predicate p to the pairs of corresponding
  30.    elements of xs and ys until p evaluates to false or one or both
  31.    lists is exhausted; returns true if p is true of all such pairs;
  32.    otherwise false.  Hence all p (xs, ys) has the same result and
  33.    effect as Lisp.all p (zip (xs, ys)).
  34.  
  35.    [exists p (xs, ys)] applies predicate p to the pairs of corresponding
  36.    elements of xs and ys until p evaluates to true or one or both
  37.    lists is exhausted; returns true if p is true of any such pair;
  38.    otherwise false.  Hence exists p (xs, ys) has the same result and
  39.    effect as Lisp.exists p (zip (xs, ys)).
  40.  
  41. *)
  42.